#include "mainscene.h"
#include "ui_mainscene.h"
#include <QPainter>
#include "mypushbutton.h"
#include <QDebug>
#include <QTimer>
MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);
    setFixedSize(320, 600);//设置固定大小
    setWindowIcon(QIcon(":/res/01.png"));//设置图标
    setWindowTitle("CoinFlip");//设置标题
    connect(ui->actionquit, &QAction::triggered, [=]() {this->close();});//退出按钮的实现
    MyPushButton* startBtn = new MyPushButton(":/res/start.png");//开始按钮
    startBtn->setParent(this);
    startBtn->move(this->width() / 2 - startBtn->width() / 2, this->height() * 0.7);
    chooseScene = new ChooseLevelScene;//实例化选择关卡场景
    connect(chooseScene,&ChooseLevelScene::chooseSceneBack,this,[=]()
            {
                this->setGeometry(chooseScene->geometry());
                chooseScene->hide();//将选择关卡场景隐藏
                this->show();
            });//重新显示主场景
    connect(startBtn, &MyPushButton::clicked, [=]()
            {
                startBtn->zoom1();//弹起特效
                startBtn->zoom2();
                QTimer::singleShot(500, this, [=]() {
                    chooseScene->setGeometry(this->geometry());//固定场景位置不变
                    this->hide();//进入到选择关卡场景中,自身隐藏
                    chooseScene->show();//显示选择关卡场景
                });//延时进入到选择的场景
            });
}
void MainScene::paintEvent(QPaintEvent*)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/levelscene.png");//插入levelscene
    painter.drawPixmap(0, 0, this->width(), this->height(), pix);
    pix.load(":/res/tittle.png");//插入tittle
    painter.drawPixmap(0, 0, pix);
}
MainScene::~MainScene()
{
    delete ui;
}


